#if 0

#include <math.h>
#include "novaFractal.h"
#include "../common/glBitmap.h"

/*==========================================================================*/

/*==========================================================================*/

struct nvComplex
{
	float r;
	float i;

	nvComplex(float a, float b) : r(a), i(b) 
	{ }

	float squareLength() 
	{
		return r * r + i * i;
	}

	nvComplex operator*(const float a)
	{
		return nvComplex(r*a, i*a);
	}
	nvComplex operator*(const nvComplex& a)
	{
		return nvComplex(r*a.r - i*a.i, i*a.r + r*a.i);
	}

	nvComplex operator+(const nvComplex& a)
	{
		return nvComplex(r+a.r, i+a.i);
	}
	nvComplex operator-(const nvComplex& a)
	{
		return nvComplex(r-a.r, i-a.i);
	}
	nvComplex operator-(const float real)
	{
		return nvComplex(r - real, i);
	}
	nvComplex operator/(nvComplex& a)
	{
		float len = a.squareLength();
		if (len < 1.2E-7)
			return *this;
		return nvComplex((r*a.r + i*a.i)/len, (i*a.r - r*a.i)/len);
	}
	nvComplex operator=(const nvComplex& a)
	{
		r = a.r;  i = a.i;
		return *this;
	}
	nvComplex power3()
	{
		return nvComplex(r*r*r - 3*r*i*i, 3*r*r*i - i*i*i);
	}
	nvComplex power2()
	{
		return nvComplex(r*r - i*i, 2*r*i);
	}
};
/*==========================================================================*/

/*==========================================================================*/

float nova(int x, int y)
{
	nvComplex R(0.8f, 0.2f);
	nvComplex c(0.1f, 0);
	float jx = SCALE * (float)(DIM/2 - x)/(DIM/2);
	float jy = SCALE * (float)(DIM/2 - y)/(DIM/2);
	nvComplex z(jx, jy);
	int i;
	float delta = 0.06f;
	nvComplex oldZ(0, 0);

	for (i = 0; i < 60 && abs(delta) > 0.05f; ++i) 
	{
		z = z - R*((z.power3() - 1)/(z.power2()*3)) + c;
		delta = (z - oldZ).squareLength();
		oldZ = z;
	}

	return (1 - i/60.0f);
}

void kernel(unsigned char *ptr)
{
	int offset;
	for (int y = 0; y < DIM; ++y)
	{
		for (int x = 0; x < DIM; ++x)
		{
			offset = x + y * DIM;
			/*
			int idx = 64 - 64*nova(x, y);
			ptr[offset*4 + 0] = COLORMAP_RED[idx];
			ptr[offset*4 + 1] = COLORMAP_GREEN[idx];
			ptr[offset*4 + 2] = COLORMAP_BLUE[idx];
			*/
			ptr[offset*4 + 0] = 
				ptr[offset*4 + 1] = 
				ptr[offset*4 + 2] = 255 * nova(x, y);
			ptr[offset*4 + 3] = 255;
		}
	}
}

int main( void )
{
	GlBitmap bitmap(DIM, DIM);
	kernel(bitmap.get_data());
	bitmap.display_and_exit();
	return 0;
}

#endif